import Vue from 'vue'
import VueRouter from 'vue-router'
// import MyHight from '@/components/MyHight.vue'
// import MyLow from '@/components/MyLow.vue'
import TableOne from '@/components/TableOne.vue'
import TableTwo from '@/components/TableTwo.vue'
import AboutTable from '@/components/AboutTable.vue'
import MovieLike from '@/components/MovieLike.vue'
import App from '@/App.vue'

// 把VueRouter安装为vue插件
Vue.use(VueRouter)

// 创建路由实例
const router = new VueRouter({
  routes: [
    // { path: '/', redirect: '/home' },
    { path: '/home', component: App },
    // { path: '/hight', component: MyHight },
    // { path: '/low', component: MyLow },
    {
      path: '/about',
      component: AboutTable,
      children: [
        { path: 'tab1', component: TableOne },
        { path: 'tab2', component: TableTwo }
      ]
    },
    { path: '/movie/:id', component: MovieLike }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.path === '/main') {
    const token = localStorage.getItem('token')
    if (token) {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
})
// 对外共享对象
export default router
